package com.example.mrzhou.lvmm.view.adapter.home;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.mrzhou.lvmm.R;
import com.example.mrzhou.lvmm.commom.utils.ImageLoader;
import com.example.mrzhou.lvmm.entity.home.HomeContent;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Mr.zhou on 2016/10/28.
 */

public class HomeContentAdapter extends RecyclerView.Adapter<HomeContentAdapter.HCViewHolder> {

    private List<HomeContent.DatasBean.InfosBean> data;
    private Context context;

    public HomeContentAdapter(List<HomeContent.DatasBean.InfosBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public HCViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new HCViewHolder(LayoutInflater.from(context).inflate(R.layout.item_list_home_nsy, parent, false));
    }

    @Override
    public void onBindViewHolder(HCViewHolder holder, int position) {
        ImageLoader.getInstance().displayImage(data.get(position).getLargeImage(),context,holder.ivHomeNsyImg,R.drawable.hot_loading,R.drawable.hot_loading);
        holder.tvHomeNsyType.setText(data.get(position).getProductTypeStr());
        holder.tvHomeNsyPrice.setText("¥"+data.get(position).getPrice()+"起");
        holder.tvHomeNsyTitle.setText(data.get(position).getTitle());
        holder.tvHomeNsyContent.setText(data.get(position).getContent());
    }

    @Override
    public int getItemCount() {
        return data != null ? data.size() : 0;
    }

    public class HCViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_home_nsy_img)
        ImageView ivHomeNsyImg;
        @BindView(R.id.tv_home_nsy_type)
        TextView tvHomeNsyType;
        @BindView(R.id.tv_home_nsy_price)
        TextView tvHomeNsyPrice;
        @BindView(R.id.tv_home_nsy_title)
        TextView tvHomeNsyTitle;
        @BindView(R.id.tv_home_nsy_content)
        TextView tvHomeNsyContent;

        public HCViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
